package com.ufcg.lvc.client.prototipacao;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.ufcg.lvc.client.GreetingService;
import com.ufcg.lvc.client.GreetingServiceAsync;
import com.ufcg.lvc.client.GreetingServiceCRUD;
import com.ufcg.lvc.client.GreetingServiceCRUDAsync;
import com.ufcg.lvc.client.Teste__;
import com.ufcg.lvc.client.UserData;

public class Inicio {
	
    AbsolutePanel rootPanel;
    List<String> listaTitulos;
    final UserData UD;
          
    public Inicio(UserData uD) {     	
    	UD = uD;
    	
		getServicoCRUD().getNomeUsuario(UD.getId_usuario(), new AsyncCallback<String>() {
			@Override
			public void onSuccess(String result) {
				Label lblBemVindo = new Label("Bem vindo, " + result.split(" ")[0]);
		        lblBemVindo.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		        rootPanel.add(lblBemVindo, 238, 16);
			}
			@Override
			public void onFailure(Throwable caught) {
				Label lblBemVindo = new Label("Bem vindo");
		        lblBemVindo.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		        rootPanel.add(lblBemVindo, 238, 16);
			}
		});        	
    		
		getServico().getDataAtual(new AsyncCallback<String>() {
			
			@Override
			public void onSuccess(String result) {
				Label dateLabel = new Label(result);
		        dateLabel.setWordWrap(false);
		        rootPanel.add(dateLabel, 970, 16);
		        rootPanel.setVisible(true);
			}
			
			@Override
			public void onFailure(Throwable caught) {		
			}
		});
		
        System.out.println("Tela inicial");
               
        // Add the nameField and sendButton to the RootPanel
        // Use RootPanel.get() to get the entire body element
        rootPanel = new AbsolutePanel();
        rootPanel.setStyleName("dialogVPanel");
        rootPanel.setSize("1160px", "790px");

        rootPanel.getElement().getStyle().setPosition(Position.RELATIVE);
        AbsolutePanel menuPanel = new AbsolutePanel();
        menuPanel.setStyleName("gwt-panelColorido");
        rootPanel.add(menuPanel, 0, 0);
        menuPanel.setSize("232px", "877px");

        VerticalPanel painelMenu = new VerticalPanel();
        painelMenu.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        painelMenu.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        menuPanel.add(painelMenu, 1, 88);
        painelMenu.setSize("250px", "276px");

        AbsolutePanel absolutePanel_2 = new AbsolutePanel();
        absolutePanel_2.setStyleName("gwt-Separador");
        painelMenu.add(absolutePanel_2);
        absolutePanel_2.setSize("252px", "1px");

        final ScrollPanel scrollPanel = new ScrollPanel();
        rootPanel.add(scrollPanel, 238, 64);
        scrollPanel.setSize("905px", "712px");

        Button btnQuestoes = new Button("Questões");
        btnQuestoes.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                final MinhasQuestoes m = new MinhasQuestoes(UD);
                scrollPanel.clear();
                scrollPanel.add(m.getPanel());
            }
        });
        btnQuestoes.setStyleName("gwt-Button_invisivel-Branco");
        painelMenu.add(btnQuestoes);
        btnQuestoes.setWidth("247px");

        AbsolutePanel absolutePanel_1 = new AbsolutePanel();
        painelMenu.add(absolutePanel_1);
        absolutePanel_1.setStyleName("gwt-Separador");
        absolutePanel_1.setSize("252px", "1px");

        Button btnModelosdeProva = new Button("Modelos de prova");
        btnModelosdeProva.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                final MeusModelosDeProva m = new MeusModelosDeProva(UD);
                scrollPanel.clear();
                scrollPanel.add(m.getPanel());
            }
        });
        btnModelosdeProva.setText("Modelos de prova");
        btnModelosdeProva.setStyleName("gwt-Button_invisivel-Branco");
        painelMenu.add(btnModelosdeProva);
        btnModelosdeProva.setWidth("247px");

        AbsolutePanel absolutePanel_3 = new AbsolutePanel();
        absolutePanel_3.setStyleName("gwt-Separador");
        painelMenu.add(absolutePanel_3);
        absolutePanel_3.setSize("252px", "1px");

        Button btnAlunos = new Button("Alunos");
        btnAlunos.setStyleName("gwt-Button_invisivel-Branco");
        painelMenu.add(btnAlunos);
        btnAlunos.setWidth("247px");
        btnAlunos.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                final MeusAlunos m = new MeusAlunos(UD);
                scrollPanel.clear();
                scrollPanel.add(m.getPanel());                          
            }
        });

        AbsolutePanel absolutePanel_4 = new AbsolutePanel();
        absolutePanel_4.setStyleName("gwt-Separador");
        painelMenu.add(absolutePanel_4);
        absolutePanel_4.setSize("252px", "1px");

        Button btnTurmas = new Button("Turmas");
        btnTurmas.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                final MinhasTurmas m = new MinhasTurmas(UD);
                scrollPanel.clear();
                scrollPanel.add(m.getPanel());
            }
        });
        btnTurmas.setStyleName("gwt-Button_invisivel-Branco");
        painelMenu.add(btnTurmas);
        btnTurmas.setWidth("247px");

        AbsolutePanel absolutePanel_5 = new AbsolutePanel();
        absolutePanel_5.setStyleName("gwt-Separador");
        painelMenu.add(absolutePanel_5);
        absolutePanel_5.setSize("252px", "1px");

        Button btnInstituicoes = new Button("Instituições"); 
        
        btnInstituicoes.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
            	MinhasInstituicoes m = new MinhasInstituicoes(UD);
                scrollPanel.clear();
                scrollPanel.add(m.getPanel());
            }
        });
        btnInstituicoes.setStyleName("gwt-Button_invisivel-Branco");
        painelMenu.add(btnInstituicoes);
        btnInstituicoes.setWidth("247px");

        AbsolutePanel absolutePanel_6 = new AbsolutePanel();
        absolutePanel_6.setStyleName("gwt-Separador");
        painelMenu.add(absolutePanel_6);
        absolutePanel_6.setSize("252px", "1px");

        Button btnConfiguraes = new Button("Configurações");
        btnConfiguraes.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                ConfigurarConta c = new ConfigurarConta(UD);
                scrollPanel.clear();
                scrollPanel.add(c.getPanel());
            }
        });
        btnConfiguraes.setStyleName("gwt-Button_invisivel-Branco");
        painelMenu.add(btnConfiguraes);
        btnConfiguraes.setWidth("247px");

        AbsolutePanel absolutePanel_7 = new AbsolutePanel();
        absolutePanel_7.setStyleName("gwt-Separador");
        painelMenu.add(absolutePanel_7);
        absolutePanel_7.setSize("252px", "1px");

        Button btnCorrigeFacil = new Button("Corrige fácil");
        btnCorrigeFacil.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                        scrollPanel.clear();
                }
        });
        btnCorrigeFacil.setStyleName("gwt-TituloGrande-P-para_Button");
        btnCorrigeFacil.setText("Corrige Fácil");
        menuPanel.add(btnCorrigeFacil, 1, 21);
        btnCorrigeFacil.setSize("231px", "61px");

        AbsolutePanel absolutePanel_8 = new AbsolutePanel();
        absolutePanel_8.setStyleName("gwt-Separador");
        rootPanel.add(absolutePanel_8, 238, 45);
        absolutePanel_8.setSize("912px", "3px");

        Button btnSair = new Button("Sair");
        btnSair.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                	telaInicial();
                }
        });
        btnSair.setStyleName("gwt-Button_invisivel_com_Borda");
        rootPanel.add(btnSair, 1048, 10);
        btnSair.setSize("102px", "29px");
        
    }
         
    private void telaInicial() {
		rootPanel.clear();
		Teste__ i = new Teste__();
		i.onModuleLoad();
	}
    public AbsolutePanel getPanel() {
        return rootPanel;
    }

    public static GreetingServiceCRUDAsync getServicoCRUD() {
		return GWT.create(GreetingServiceCRUD.class);
	}
    
    public static GreetingServiceAsync getServico() {
		return GWT.create(GreetingService.class);
	}
    
}
